﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Screen_Move : MonoBehaviour
{
    public float moveSpeed = 3.0f;
    public Camera bodyCamera;
    private bool needReset = false;

    private Vector3 cam_normal_pos;
    private Vector3 cam_target_pos;
    private float cam_normal_FieldView = 60;
    private float cam_target_FieldView = 40;
    private float normal_Speed;
    private float target_Speed;

    public Transform gunTrans;
    private void Start()
    {
        cam_normal_pos = bodyCamera.transform.localPosition;
        cam_target_pos = new Vector3(0.61f, 1.86f, -0.84f);
        normal_Speed = moveSpeed;
        target_Speed = 1.5f;
    }

    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * moveSpeed;
        float mouseY = Input.GetAxis("Mouse Y") * moveSpeed;
        if ((gunTrans.transform.localRotation * Quaternion.Euler(-mouseY, 0, 0)).eulerAngles.x >= 350 || (gunTrans.transform.localRotation * Quaternion.Euler(-mouseY, 0, 0)).eulerAngles.x <= 10)
        {
            gunTrans.transform.localRotation = gunTrans.transform.localRotation * Quaternion.Euler(-mouseY, 0, 0);
        }
        transform.localRotation = transform.localRotation * Quaternion.Euler(0, mouseX, 0);

        if (Input.GetMouseButton(1))
        {
            bodyCamera.transform.localPosition = cam_target_pos;
            bodyCamera.fieldOfView = cam_target_FieldView;
            moveSpeed = target_Speed;
        }
        if (Input.GetMouseButtonUp(1))
        {
            bodyCamera.transform.localPosition = cam_normal_pos;
            bodyCamera.fieldOfView = cam_normal_FieldView;
            moveSpeed = normal_Speed;
        }

    }
}
